﻿namespace LogManager.Gui.Views
{
    using LogManager.Gui.Helpers;
    using LogManager.Gui.UI.Helpers;
    using LogManager.Gui.ViewModels;
    using System.Windows;
    using System.Windows.Controls;

    /// <summary>
    /// Interaction logic for TestAllLocations.xaml
    /// </summary>
    public partial class ExecuteArchivingView : UserControl, IExecuteArchivingView
    {
        public IExecuteArchivingViewModel ViewModel
        {
            get { return this.GetViewModelFromDataContext<IExecuteArchivingViewModel>(); }
            set { this.DataContext = value; }
        }

        public ExecuteArchivingView()
        {
            InitializeComponent();
        }

        public bool BringIntoView(object itemToSelect)
        {
            var item = TreeViewHelpers.GetTreeViewItem(this.TreeView1, itemToSelect);
            if (item != null)
            {
                item.BringIntoView();
                return true; ;
            }
            return false;
        }

        private void TreeView1Item_selected(System.Object sender, System.Windows.RoutedEventArgs e)
        {
            var treeView = (TreeView)e.Source;
            this.ViewModel.OnTreeItemSelected(treeView.SelectedValue);
        }
    }
}
